package demo.base.connect.conf;

import org.apache.flink.api.java.utils.ParameterTool;

import java.io.IOException;
import java.io.InputStream;

public class PropertyReader {

    //    public static PropertyReader init(String propFilePath) {
    //        try {
    //            if(propFilePath.equals("order.properties")) {
    //                param = getReader(propFilePath);
    //            } else {
    //                System.out.println("PropertyReader propFilePath Error");
    //            }
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //        } finally {
    //            return new PropertyReader();
    //        }
    //    }

    public static ParameterTool getReader(String filePath) throws IOException {
        if (filePath.equals("order.properties")) {
            InputStream resourceAsStream =
                    PropertyReader.class.getClassLoader().getResourceAsStream(filePath);
            return ParameterTool.fromPropertiesFile(resourceAsStream);
        } else {
            System.out.println("Can not find the file path: " + filePath);
            return null;
        }
    }

    public static void main(String[] args) {
        ParameterTool reader = null;
        try {
            reader = PropertyReader.getReader("order.properties");
            System.out.println(reader.getNumberOfParameters());
            System.out.println(reader.getConfiguration().keySet());
            System.out.println(reader.getProperties().keySet());
            System.out.println(reader.get("sum"));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
